<?php
	class GoodsTypeControl extends AuthControl{
		public function index(){
			$db = K('GoodsType');
			$data = $db->order('gt_id')->all();
			$this->assign('data',$data);
			$this->display();
		}

		public function add(){
			if(IS_POST){
				$model = K('GoodsType');
				if($model->addGoodsType($_POST)){
					$this->dataCatch();
					$this->success('添加成功',U('index'));
					
				}else{
					$this->error($model->error);
				}

			}else{
				$this->display();
			}
		}
		public function del(){
			$model = K('GoodsType');
			if($model->delGoodsType(Q('gt_id'))){
				$this->success('删除成功',U('index'));

			}else{
				$this->error($model->error);
			}
		}

		public function save(){
			$model = K('GoodsType');
			$data = $model->where(array('gt_id'=>Q('gt_id')))->all();

			if(IS_POST){
				if($model->updateGoodsType(Q('gt_id'))){
					$this->success('修改成功',U('index'));
				}else{
					$this->error($model->error);
				}
			}else{
				$this->assign('data',$data);
				$this->display();
			}
		}

		public function dataCatch(){
			$model = K('GoodsType');
			if($model->dataCatch()){
				$this->success('更新缓存',U('index'));
			}else{
				$this->error($model->error);
			}
		}
	}
?>
